home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / prnmain / demo.pas < prev    next >
Pascal/Delphi Source File  |  1996-04-08  |  8KB  |  240 lines

  1. {******* demo.pas *******}
  2.  
  3. unit Demo;
  4.  
  5.  
  6. interface
  7.  
  8. uses
  9.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  10.   Forms, Dialogs, ExtCtrls, StdCtrls, Mask, DBCtrls, Menus, PrnMain;
  11.  
  12. const
  13.   LeftMargin = 0.5;
  14.   RightMargin = 0.5;
  15.   TopMargin = 0.5;
  16.   BottomMargin = 0.5;
  17.  
  18. type
  19.   TPrintForm = class(TForm)
  20.    Button1: TButton;
  21.    Button2: TButton;
  22.    PixelsPerInch: TPanel;
  23.    PixelsPerPage: TPanel;
  24.    Gutters: TPanel;
  25.    LineHeight: TPanel;
  26.    FontInformation: TPanel;
  27.    LinesInDetailArea: TPanel;
  28.  
  29.    procedure Button1Click(Sender: TObject);
  30.    procedure FormCreate(Sender: TObject);
  31.    procedure Button2Click(Sender: TObject);
  32.   private
  33.    { Private declarations }
  34.   public
  35.    { Public declarations }
  36.   end;
  37.  
  38. var
  39.   PrintForm: TPrintForm;
  40.   Prn: TPrintObject;
  41.  
  42. implementation
  43.  
  44. {$R *.DFM}
  45.  
  46. procedure TPrintForm.Button1Click(Sender: TObject);
  47.  
  48.   var
  49.      Buffer: String;
  50.      Code: String[10];
  51.      ECHOCode: String[10];
  52.      HeaderLine: Boolean;
  53.      I: Word;
  54.  
  55.  
  56.   Begin
  57.   { Define the dimensions of the header area.  I want the header area
  58.     lightly shaded.  If I wanted no shading, the last parameter would be
  59.     255. }
  60.   with prn do 
  61.   begin
  62.     SetHeaderDimensions( 0.25,0.25,8.25,1.25,True,0,225 );
  63.  
  64.     { Define two header lines }
  65.     SetHeaderInformation( 1,0.5,'This is header line number 1',1,'Arial',14,[fsBold] );
  66.     SetHeaderInformation( 2,1.0,DateToStr(Date),1,'Arial',11,[] );
  67.  
  68.     { Define the dimensions of the footer area.  I want the footer area
  69.  
  70.       lightly shaded.  If I wanted no shading, the last parameter would be
  71.       255. }
  72.     SetFooterDimensions( 0.25,9.40,8.25,10.20,True,0,225 );
  73.  
  74.     { Define two footer lines }
  75.     SetFooterInformation( 1,9.5,'This is footer line number 1',1,'Arial',14,[fsBold] );
  76.     SetFooterInformation( 2,9.85,'This is footer line number 2',1,'Arial',12,[fsBold] );
  77.  
  78.     { I would like page numbering, right justified on the very bottom of the
  79.       page. }
  80.     SetPageNumberInformation( 10.25,'Page: %d',2,'Arial',9,[fsBold] );
  81.  
  82.  
  83.     { Set the current position to the top of the detail area }
  84.     SetTopOfPage;
  85.  
  86.     { Write three lines, the first left justified, the second centered and
  87.       the third right justified.  The first line gets printed two inches
  88.       from the top.  The next two lines get printed at the next line from
  89.       the previous line. The '-1' for the first parameter indicates that
  90.       printing should be on the next line.  If '-2' is passed as a 
  91.       parameter, printing would occur on the current line. }
  92.  
  93.     WriteLine( -1.0,2.0,'This is a line left justified' );
  94.     WriteLineCenter( -1.0,'This is a line centered' );
  95.     WriteLineRight( -1.0,'This is a line right justified' );
  96.  
  97.     { Create five columns.  The first parameter is the column number, the
  98.       second parameter is the location in inches from the left and the third
  99.       parameter is the length in inches. }
  100.     CreateColumn( 1,0.25,1.5 );
  101.     CreateColumn( 2,1.80,1.5 );
  102.     CreateColumn( 3,3.35,1.5 );
  103.     CreateColumn( 4,4.90,1.5 );
  104.  
  105.     CreateColumn( 5,6.50,1.5 );
  106.  
  107.     { Start writing column text (left justified) at three inches from the 
  108.       top }
  109.     SetYPosition( 3.0 );
  110.     For I := 1 To 10 Do
  111.        Begin
  112.        { The first parameter of 'WriteLineColumn' is the column number and
  113.          the second parameter indicates that printing should occur on the
  114.          current line (in this case, three inches from the top).  If the 
  115.          second parameter was -1, printing would occur on the next line. }
  116.  
  117.        WriteLineColumn( 1,-2,Format('Column 1, Line %d',[I]) );
  118.        WriteLineColumn( 2,-2,Format('Column 2, Line %d',[I]) );
  119.        WriteLineColumn( 3,-2,Format('Column 3, Line %d',[I]) );
  120.        WriteLineColumn( 4,-2,Format('Column 4, Line %d',[I]) );
  121.        WriteLineColumn( 5,-2,Format('Column 5, Line %d',[I]) );
  122.        { Generate a line feed }
  123.        NextLine;
  124.        End;
  125.                                                              
  126.     { Start writing column text (right justified) at six inches from the 
  127.  
  128.       top }
  129.     SetYPosition( 5.0 );
  130.     For I := 1 To 10 Do
  131.        Begin
  132.        WriteLineColumnRight( 1,-2,Format('Column 1, Line %d',[I]) );
  133.        WriteLineColumnRight( 2,-2,Format('Column 2, Line %d',[I]) );
  134.        WriteLineColumnRight( 3,-2,Format('Column 3, Line %d',[I]) );
  135.        WriteLineColumnRight( 4,-2,Format('Column 4, Line %d',[I]) );
  136.        WriteLineColumnRight( 5,-2,Format('Column 5, Line %d',[I]) );
  137.        NextLine;
  138.        End;
  139.                                                              
  140.  
  141.     { Start writing column text (centered) at seven inches from the 
  142.       top }
  143.     SetYPosition( 7.0 );
  144.     For I := 1 To 10 Do
  145.        Begin
  146.        WriteLineColumnCenter( 1,-2,Format('Column 1, Line %d',[I]) );
  147.        WriteLineColumnCenter( 2,-2,Format('Column 2, Line %d',[I]) );
  148.        WriteLineColumnCenter( 3,-2,Format('Column 3, Line %d',[I]) );
  149.        WriteLineColumnCenter( 4,-2,Format('Column 4, Line %d',[I]) );
  150.        WriteLineColumnCenter( 5,-2,Format('Column 5, Line %d',[I]) );
  151.  
  152.        NextLine;
  153.        End;
  154.  
  155.     { Start a new page }
  156.     NewPage;
  157.  
  158.     { Change the font information }
  159.     SetFontInformation( 'Courier',20,[fsBold,fsUnderline] );
  160.  
  161.     For I := 1 To 10 Do
  162.        WriteLine( LeftMargin,-1,Format('This is line %d',[I]) );
  163.  
  164.     { Set a tab of .5 inches }
  165.     SetTab( 0.5 );
  166.  
  167.     { Change the font information }
  168.     SetFontInformation( 'Arial',10,[fsItalic] );
  169.     NextLine;
  170.     For I := 1 To 10 Do
  171.        { Since a tab of .5 is set, this text will actually get printed at
  172.  
  173.          1.0 inches from the left }
  174.        WriteLine( LeftMargin,-1,Format('This is line %d',[I]) );
  175.  
  176.     { Draw some lines of varying thickness }
  177.     DrawLine( 2.5,5.0,6.0,8.5,5 );
  178.     DrawLine( 6.2,5.2,3.0,8.7,20 );
  179.                                                             
  180.     { We're all done.  Always call 'Quit' }
  181.     Quit;
  182.     Free;
  183.     Exit;
  184.   end;
  185. End;
  186.  
  187. procedure TPrintForm.FormCreate(Sender: TObject);
  188. var
  189.   X,Y: Word;
  190.   Top,Bottom,Left,Right: Word;
  191.  
  192.  
  193. Begin
  194.     { Create a TPrintObject }
  195.     Prn := TPrintObject.Create;
  196.     with prn do 
  197.     begin
  198.  
  199.     { Must always call 'Start' first thing }
  200.     Start;
  201.  
  202.     { Set left, right, top and bottom margins - in inches }
  203.     SetMargins( LeftMargin,RightMargin,TopMargin,BottomMargin );
  204.  
  205.     { Define what the 'detail' section dimensions will be.  The detail section
  206.       is the space between the header and the footer areas. }
  207.     SetDetailTopBottom( 1.4,9.4 );
  208.  
  209.     { Set default information }
  210.  
  211.     SetFontInformation( 'Arial',11,[] ); 
  212.  
  213.     GetPixelsPerInch( X,Y );
  214.     PixelsPerInch.Caption := Format( 'Pixels Per Inch      X: %d  Y: %d',[X,Y] );
  215.  
  216.     GetPixelsPerPage( X,Y );
  217.     PixelsPerPage.Caption := Format( 'Pixels Per Page      X: %d  Y: %d',[X,Y] );
  218.  
  219.     GetGutter( Top,Bottom,Left,Right );
  220.     Gutters.Caption := Format( 'Gutters     Top: %d   Bottom: %d   Left: %d   Right: %d',[Top,Bottom,Left,Right] );
  221.  
  222.     LineHeight.Caption := Format( 'Height of Each Line:   %d',[GetLineHeightPixels] );
  223.  
  224.  
  225.     FontInformation.Caption := Format( 'Font Name: %s     Font Size: %d',[GetFontName,GetFontSize] );
  226.  
  227.     LinesInDetailArea.Caption := Format( 'Lines in Detail Area: %d',[GetLinesInDetailArea] );
  228.     end; {with}
  229. End;
  230.  
  231. procedure TPrintForm.Button2Click(Sender: TObject);
  232.  
  233.   Begin
  234.   Close;
  235.   Halt;
  236.   End;
  237.  
  238. end.
  239.  
  240.